import 'package:flutter/cupertino.dart';
import 'package:flutter_magic_planet/common/app_router.dart';
import 'package:flutter_magic_planet/component/toast.dart';
import 'package:flutter_magic_planet/module/video/video_list/video_list_view.dart';
import 'package:get/get.dart';

class SearchLogic extends GetxController {
  final dropValue = 'title'.obs;
  final dropItems = {'标题': 'title', '导演': 'author'};
  late TextEditingController textController;
  final searchUnits = ['视频', '小说', '漫画'];
  final searchUnitIndex = 0.obs;

  @override
  void onInit() {
    super.onInit();
    textController = TextEditingController();
  }

  void setDropSelected(String value) {
    dropValue.value = value;
    update();
  }

  void setSearchUnitSelected(int value) {
    searchUnitIndex.value = value;
  }

  /// 根据radio打开不同的搜索结果
  void searchToPage({required String query, String? option}) {
    switch (searchUnitIndex.value) {
      case 0:
        Get.to(() => VideoListPage(query: query, option: option ?? ''));
        break;
      case 1:
        Toast.show('开发中');
        break;
      case 2:
        AppRouter.toComicList(query, option ?? '');
    }
  }
}
